//
//  ReportBuildVC.m
//  efairy
//
//  Created by 李锋 on 2019/3/22.
//  Copyright © 2019年 East. All rights reserved.
//

#import "ReportBuildVC.h"
#import "ReportProjectItemCell.h"
#import "ApiManager.h"
#import "EFAModel.h"
#import "ReportDetailVC.h"
#import "XJTimePickView.h"

@interface ReportBuildVC ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
@property(nonatomic, strong)UIButton *submitBtn;
@property(nonatomic, strong)UIView  *bulidCondition;
@property(nonatomic, strong)UITableView *tableView;
@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)UITextField *textField;
@property(nonatomic, strong)UIView *quickView;
@property(nonatomic, strong)UILabel *quickTitle;
@property(nonatomic, strong)UIButton *thirtyDay;
@property(nonatomic, strong)UIButton *sevenDay;
@property(nonatomic, strong)UIButton *oneDay;
@property(nonatomic, strong)UIView *dateView;
@property(nonatomic, strong)UILabel *startDateTitle;
@property(nonatomic, strong)UILabel *endDateTitle;
@property(nonatomic, strong)UILabel *startDate;
@property(nonatomic, strong)UILabel *endDate;
@property(nonatomic, strong)UIImageView *startArrow;
@property(nonatomic, strong)UIImageView *endArrow;
@property(nonatomic, strong)UIView *line;
@property(nonatomic, strong)UIView *line2;

@property(nonatomic, strong)NSString *startTime;
@property(nonatomic, strong)NSString *endTime;
@property (strong,nonatomic) UIView *dateContentView;
@property (strong,nonatomic) UIView *statrDateView;
@property (strong,nonatomic) UIView *endDateView;
@property(nonatomic, strong) XJTimePickView *startTimePickView;
@property(nonatomic, strong) XJTimePickView *endTimePickView;
@property(nonatomic, strong) UIButton *cancel;
@property(nonatomic, strong) UIButton *confirm;

@end

@implementation ReportBuildVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavigationBar];
    [self initView];
}

-(void)setNavigationBar{
    self.navigationItem.title=@"生成报告";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"global_nav_back"] style:UIBarButtonItemStylePlain target:self action:@selector(backVC)];
}

- (void)backVC {
    //返回上一界面
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)initView{
    self.view.backgroundColor = ColorFromRGB(0xeff0f4);
    _submitBtn = [[UIButton alloc]initWithFrame:CGRectMake(20, SCREEN_HEIGHT-68, self.view.frame.size.width-40, 48)];
    _submitBtn.backgroundColor = ColorFromRGB(0x282449);
    [_submitBtn setTitle:@"生成报告" forState:UIControlStateNormal];
    [_submitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _submitBtn.titleLabel.font = [UIFont boldSystemFontOfSize:17.0f];
    _submitBtn.layer.cornerRadius = 24;
    [_submitBtn addTarget:self action:@selector(onclickSubmit) forControlEvents:UIControlEventTouchUpInside];
    
    _bulidCondition = [[UIView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT-20-178-68, self.view.frame.size.width, 178)];
    _bulidCondition.backgroundColor = [UIColor whiteColor];

    _titleLabel  = [[UILabel alloc]init];
    _titleLabel.textColor = ColorFromRGB(0x333333);
    _titleLabel.font = [UIFont systemFontOfSize:14.0f];
    _titleLabel.text = @"报告标题";
    
    _textField  = [[UITextField alloc]init];
    _textField.textColor = ColorFromRGB(0x333333);
    _textField.placeholder = @"请在这里输入标题";
    
    _line = [[UIView alloc]init];
    _line.backgroundColor = ColorFromRGB(0xe5e5e5);
    
    _quickView  = [[UIView alloc]init];
    _quickTitle  = [[UILabel alloc]init];
    _quickTitle.text = @"快捷方式";
    _quickTitle.font = [UIFont systemFontOfSize:14.0f];
    
    _thirtyDay  = [[UIButton alloc]init];
    _thirtyDay.tag = 30;
    _thirtyDay.backgroundColor = [UIColor whiteColor];
    [_thirtyDay setTitle:@"近30天" forState:UIControlStateNormal];
    [_thirtyDay setTitleColor:ColorFromRGB(0x333333) forState:UIControlStateNormal];
    _thirtyDay.layer.borderColor = [ColorFromRGB(0xe5e5e5) CGColor];
    _thirtyDay.layer.borderWidth = 1;
    _thirtyDay.layer.cornerRadius = 15;
    _thirtyDay.titleLabel.font = [UIFont systemFontOfSize:14.0f];
    [_thirtyDay addTarget:self action:@selector(onclickQuickBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    
    _sevenDay  = [[UIButton alloc]init];
     _sevenDay.tag = 7;
    _sevenDay.backgroundColor = ColorFromRGB(0x282449);
    [_sevenDay setTitle:@"近7天" forState:UIControlStateNormal];
    [_sevenDay setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _sevenDay.layer.borderColor = [ColorFromRGB(0xe5e5e5) CGColor];
    _sevenDay.layer.borderWidth = 1;
    _sevenDay.layer.cornerRadius = 15;
    _sevenDay.titleLabel.font = [UIFont systemFontOfSize:14.0f];
    [_sevenDay addTarget:self action:@selector(onclickQuickBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    _oneDay  = [[UIButton alloc]init];
    _oneDay.tag = 0;
    _oneDay.backgroundColor = [UIColor whiteColor];
    [_oneDay setTitle:@"本日" forState:UIControlStateNormal];
    [_oneDay setTitleColor:ColorFromRGB(0x333333) forState:UIControlStateNormal];
    _oneDay.layer.borderColor = [ColorFromRGB(0xe5e5e5) CGColor];
    _oneDay.layer.borderWidth = 1;
    _oneDay.layer.cornerRadius = 15;
    _oneDay.titleLabel.font = [UIFont systemFontOfSize:14.0f];
    [_oneDay addTarget:self action:@selector(onclickQuickBtn:) forControlEvents:UIControlEventTouchUpInside];
    [_quickView sd_addSubviews:@[_quickTitle,_thirtyDay,_sevenDay,_oneDay]];
    _quickTitle.sd_layout.widthIs(70).heightIs(44).leftSpaceToView(_quickView, 12);
     _oneDay.sd_layout.widthIs(66).heightIs(30).rightSpaceToView(_quickView, 20).topSpaceToView(_quickView, 7);
     _sevenDay.sd_layout.widthIs(66).heightIs(30).rightSpaceToView(_oneDay, 20).topSpaceToView(_quickView, 7);
    _thirtyDay.sd_layout.widthIs(66).heightIs(30).rightSpaceToView(_sevenDay, 20).topSpaceToView(_quickView, 7);
    
    _line2 = [[UIView alloc]init];
    _line2.backgroundColor = ColorFromRGB(0xe5e5e5);
    
    _dateView  = [[UIView alloc]init];
    
    UITapGestureRecognizer *dateTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClickCheckDate:)];
    [_dateView addGestureRecognizer:dateTap];
    
    
    _startDateTitle  = [[UILabel alloc]init];
    _startDateTitle.textColor = ColorFromRGB(0x333333);
    _startDateTitle.font = [UIFont systemFontOfSize:14.0f];
    _startDateTitle.text = @"开始时间";

    _startDate  = [[UILabel alloc]init];
    _startDate.textColor = ColorFromRGB(0x333333);
    _startDate.font = [UIFont systemFontOfSize:14.0f];
    _startDate.textAlignment = NSTextAlignmentRight;
    
    _startArrow  = [[UIImageView alloc]init];
    _startArrow.image = [UIImage imageNamed:@"icon_right_arrow"];
    
    _endDateTitle  = [[UILabel alloc]init];
    _endDateTitle.textColor = ColorFromRGB(0x333333);
    _endDateTitle.font = [UIFont systemFontOfSize:14.0f];
    _endDateTitle.text = @"结束时间";
    
    _endDate  = [[UILabel alloc]init];
    _endDate.textColor = ColorFromRGB(0x333333);
    _endDate.font = [UIFont systemFontOfSize:14.0f];
    _endDate.textAlignment = NSTextAlignmentRight;
    
    _endArrow  = [[UIImageView alloc]init];
    _endArrow.image = [UIImage imageNamed:@"icon_right_arrow"];
    [_dateView sd_addSubviews:@[_startDateTitle,_startDate,_startArrow,_endDateTitle,_endDate,_endArrow]];
    _startDateTitle.sd_layout.widthIs(70).heightIs(44).leftSpaceToView(_dateView, 12).topSpaceToView(_dateView, 0);
    _startDate.sd_layout.widthIs(SCREEN_WIDTH-82-53).heightIs(44).leftSpaceToView(_startDateTitle, 0)
    .topSpaceToView(_dateView, 0);;
    _startArrow.sd_layout.widthIs(8).heightIs(13).topSpaceToView(_dateView, 15.5).rightSpaceToView(_dateView, 20);
    
    _endDateTitle.sd_layout.widthIs(70).heightIs(44).leftSpaceToView(_dateView, 12).topSpaceToView(_startDateTitle, 0);
    _endDate.sd_layout.widthIs(SCREEN_WIDTH-82-53).heightIs(44).leftSpaceToView(_endDateTitle, 0)
    .topSpaceToView(_startDateTitle, 0);;
    _endArrow.sd_layout.widthIs(8).heightIs(13).topSpaceToView(_dateView, 59.5).rightSpaceToView(_dateView, 20);
    
     [_bulidCondition sd_addSubviews:@[_titleLabel,_textField,_line,_quickView,_line2,_dateView,]];
    _titleLabel.sd_layout.widthIs(70).heightIs(44).leftSpaceToView(_bulidCondition, 12).topSpaceToView(_bulidCondition, 0);
    _textField.sd_layout.widthIs(SCREEN_WIDTH-92).heightIs(44).leftSpaceToView(_titleLabel, 10).topSpaceToView(_bulidCondition, 0);
    _line.sd_layout.heightIs(1).widthIs(SCREEN_WIDTH).topSpaceToView(_titleLabel, 0);
    _quickView.sd_layout.widthIs(SCREEN_WIDTH).heightIs(44).topSpaceToView(_line, 0);
     _line2.sd_layout.heightIs(1).widthIs(SCREEN_WIDTH).topSpaceToView(_quickView, 0);
    _dateView.sd_layout.widthIs(SCREEN_WIDTH).heightIs(88).topSpaceToView(_line2, 0);
    
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,SCREEN_HEIGHT-68-20-178-8)];
    _tableView.backgroundColor = ColorFromRGB(0xeff0f4);
    _tableView.delegate = self;
    _tableView.dataSource = self;
//    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;//隐藏所有分割线
    _tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];//多余分割线不显示
    
    [self.view sd_addSubviews:@[_tableView,_bulidCondition,_submitBtn]];
    
    _startTimePickView = [self statrTimePickView];
    _endTimePickView = [self endTimePickView];
    [self setupDateChooseView];
    [self getQuickDate:7];
}



-(void)onclickQuickBtn:(UIButton *)btn{
    int days = (int)btn.tag;
    if(days == 30){
        [self setQuickDayBtnColor:ColorFromRGB(0x282449) titlecolor:ColorFromRGB(0xffffff) btn:btn];
        [self setQuickDayBtnColor:ColorFromRGB(0xffffff) titlecolor:ColorFromRGB(0x333333) btn:_sevenDay];
        [self setQuickDayBtnColor:ColorFromRGB(0xffffff) titlecolor:ColorFromRGB(0x333333) btn:_oneDay];
    }else if(days == 7){
        [self setQuickDayBtnColor:ColorFromRGB(0xffffff) titlecolor:ColorFromRGB(0x333333) btn:_thirtyDay];
        [self setQuickDayBtnColor:ColorFromRGB(0x282449) titlecolor:ColorFromRGB(0xffffff) btn:btn];
        [self setQuickDayBtnColor:ColorFromRGB(0xffffff) titlecolor:ColorFromRGB(0x333333) btn:_oneDay];
    }else if(days == 0){
        [self setQuickDayBtnColor:ColorFromRGB(0xffffff) titlecolor:ColorFromRGB(0x333333) btn:_thirtyDay];
        [self setQuickDayBtnColor:ColorFromRGB(0xffffff) titlecolor:ColorFromRGB(0x333333) btn:_sevenDay];
        [self setQuickDayBtnColor:ColorFromRGB(0x282449) titlecolor:ColorFromRGB(0xffffff) btn:btn];
    }
    [self getQuickDate:days];
}

-(void)setQuickDayBtnColor:(UIColor *)bgcolor titlecolor:(UIColor *)titlecolor btn:(UIButton *)btn {
    btn.backgroundColor = bgcolor;
    [btn setTitleColor:titlecolor forState:UIControlStateNormal];
    
}

-(void)getQuickDate:(int)day{
    NSDate *currentdate = [NSDate date];
    NSTimeInterval  days = 24 * 60 * 60 * day;  //时长
//    NSDate *newDate = [currentdate dateByAddingTimeInterval:24 * 60 * 60  * day];
    // 减去
    NSDate *newDate = [currentdate initWithTimeIntervalSinceNow: -days ];
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy"];
    NSInteger currentYear = [[formatter stringFromDate:currentdate] integerValue];
    NSInteger dyear=[[formatter stringFromDate:newDate] integerValue];
    [formatter setDateFormat:@"MM"];
    NSInteger currentMonth = [[formatter stringFromDate:currentdate] integerValue];
    NSInteger dmonth=[[formatter stringFromDate:newDate]integerValue];
    [formatter setDateFormat:@"dd"];
    NSInteger currentDay = [[formatter stringFromDate:currentdate] integerValue];
    NSInteger dDay=[[formatter stringFromDate:newDate] integerValue];
    [_startTimePickView setDefaultsDate:dyear month:dmonth day:dDay];
    [_endTimePickView setDefaultsDate:currentYear month:currentMonth day:currentDay];
    _startDate.text = [NSString stringWithFormat:@"%ld-%ld-%ld",dyear,dmonth,dDay];
    _endDate.text = [NSString stringWithFormat:@"%ld-%ld-%ld",currentYear,currentMonth,currentDay];
    _startTime = _startDate.text;
    _endTime = _endDate.text;
}
    

-(void)onclickSubmit{
    [self bulidReportRequest];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(_projectArray){
        return _projectArray.count;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ReportProjectItemCell *cell = [tableView dequeueReusableCellWithIdentifier:[@"ReportProjectItemCell" description]];
    if(!cell){
        cell = [[ReportProjectItemCell alloc]init];
    }
    
   
    [cell setDataModel:_projectArray[indexPath.row].efairyproject_name];
    [cell useCellFrameCacheWithIndexPath:indexPath tableView:tableView];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [tableView cellHeightForIndexPath:indexPath cellContentViewWidth:SCREEN_WIDTH tableView:tableView];
}


//颜值搜索栏输入的长度
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if (textField == self.textField) {
        //这里的if时候为了获取删除操作,如果没有次if会造成当达到字数限制后删除键也不能使用的后果.
        if (range.length == 1 && string.length == 0) {
           
            return YES;
        }
        //so easy
        else if (self.textField.text.length >= 40) {
            self.textField.text = [textField.text substringToIndex:40];
            return NO;
        }
    }
   
    return YES;
}


-(void)bulidReportRequest{
    
    
    NSMutableArray<NSString *> *ids = [[NSMutableArray alloc]init];
    for (ReportProjectListModel *item in _projectArray) {
        [ids addObject:item.efairyproject_id];
    }
    NSDictionary *params = @{
                             @"efairyuser_id" : @([EFAModel sharedInstance].loginInfo.user_info.efairyuser_id),
                             @"access_token" : [EFAModel sharedInstance].loginInfo.access_token,
                             @"efairyreport_title":_textField.text,
                             @"start_time":_startTime,
                             @"end_time":_endTime,
                             @"efairyproject_id_list":ids
                             };
    
    NSLog(@"设备报表列表请求参数：%@",params);
    MBProgressHUD *hud = [MBProgressHUD xd_showHUDAddedTo:self.view animated:YES];
    [[XDAFNetworking sharedInstance]POST:[ApiManager apiReport] parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [hud hideAnimated:YES];
        NSDictionary *dic = responseObject;
        NSDictionary *dicid= [dic objectForKey:@"result"];
        if(dicid){
            NSNumber *reportId =  [dicid objectForKey:@"efairyreport_id"];
            if(reportId){
                [MBProgressHUD showPromptWithAutoHideInView:self.view message:@"生成报表成功"];
                ReportDetailVC *vc =[[ReportDetailVC alloc]init];
                vc.reportId = [reportId stringValue];
                [self showViewController:vc sender:nil];
            }
        }
        [MBProgressHUD showPromptWithAutoHideInView:self.view message:@"生成报表失败"];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"错误信息：%@",error);
        [hud hideAnimated:YES];
        NSString *msg = [[ApiErrorCode sharedInstance] errorCodeMsgWithError:error];
        [MBProgressHUD showPromptWithAutoHideInView:self.view message:msg];
    }];
}


-(void)setupDateChooseView{
    
    UIWindow *wd = [[UIApplication sharedApplication].windows lastObject];
    _dateContentView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    //只设置黑白背景色,这种设置方式不会导致子view也跟随透明
    _dateContentView.backgroundColor =  [UIColor colorWithWhite:0.f alpha:0.5];
    
    
    _statrDateView = [[UIView alloc] initWithFrame:CGRectMake(20, 150, SCREEN_WIDTH-40, SCREEN_HEIGHT-300)];
    _statrDateView.backgroundColor =  [UIColor whiteColor];
    
    UILabel *startDateTitle = [[UILabel alloc]init];
    startDateTitle.font = [UIFont boldSystemFontOfSize:17.f];
    startDateTitle.textColor = ColorFromRGB(0x3F3F3F);
    startDateTitle.textAlignment = NSTextAlignmentCenter;
    startDateTitle.text = @"起始时间";
    
    UILabel *endDateTitle = [[UILabel alloc]init];
    endDateTitle.font = [UIFont boldSystemFontOfSize:17.f];
    endDateTitle.textColor = ColorFromRGB(0x3F3F3F);
    endDateTitle.textAlignment = NSTextAlignmentCenter;
    endDateTitle.text = @"结束时间";
    
    _startTimePickView = [self statrTimePickView];
    _endTimePickView = [self endTimePickView];
    
    _cancel = [[UIButton alloc]init];
    [_cancel setTitle:@"取消" forState:UIControlStateNormal];
    [_cancel setTitleColor:ColorFromRGB(0x999999) forState:UIControlStateNormal];
    _cancel.titleLabel.font = [UIFont boldSystemFontOfSize:16.f];
    [_cancel addTarget:self action:@selector(cancelChooseDate:) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIView *vline = [[UIView alloc]init];
    vline.backgroundColor = ColorFromRGB(0xe5e5e5);
    
    UIView *hline = [[UIView alloc]init];
    hline.backgroundColor = ColorFromRGB(0xe5e5e5);
    
    
    _confirm = [[UIButton alloc]init];
    [_confirm setTitle:@"确定" forState:UIControlStateNormal];
    [_confirm setTitleColor:ColorFromRGB(0x282449) forState:UIControlStateNormal];
    _confirm.titleLabel.font = [UIFont boldSystemFontOfSize:16.f];
    [_confirm addTarget:self action:@selector(confirmChooseDate:) forControlEvents:UIControlEventTouchUpInside];
    
    [_statrDateView sd_addSubviews:@[startDateTitle,_startTimePickView,endDateTitle,_endTimePickView,hline,_cancel,vline,_confirm]];
    
    startDateTitle.sd_layout.widthIs(SCREEN_WIDTH-40)
    .heightIs(40)
    .topSpaceToView(_statrDateView, 0);
    
    _startTimePickView.sd_layout.widthIs(SCREEN_WIDTH-40)
    .heightIs((SCREEN_HEIGHT-425)/2)
    .topSpaceToView(startDateTitle, 0);
    
    endDateTitle.sd_layout.widthIs(SCREEN_WIDTH-40)
    .heightIs(40)
    .topSpaceToView(_startTimePickView, 20);
    
    _endTimePickView.sd_layout.widthIs(SCREEN_WIDTH-40)
    .heightIs((SCREEN_HEIGHT-425)/2)
    .topSpaceToView(endDateTitle, 0);
    
    hline.sd_layout.heightIs(1)
    .leftSpaceToView(_statrDateView, 0)
    .rightSpaceToView(_statrDateView,0)
    .bottomSpaceToView(_statrDateView, 44);
    
    _cancel.sd_layout.widthIs((SCREEN_WIDTH-40)/2-0.5).heightIs(44)
    .bottomSpaceToView(_statrDateView, 0);
    
    vline.sd_layout.widthIs(1).heightIs(20)
    .bottomSpaceToView(_statrDateView, 14)
    .leftSpaceToView(_cancel, 0);
    
    _confirm.sd_layout.widthIs((SCREEN_WIDTH-40)/2-0.5).heightIs(44)
    .leftSpaceToView(vline, 0)
    .bottomSpaceToView(_statrDateView, 0);
    
    [_dateContentView addSubview:_statrDateView];
    [wd addSubview:_dateContentView];
    _dateContentView.hidden = YES;
    
}

- (XJTimePickView *)statrTimePickView{
    if (!_startTimePickView) {
        _startTimePickView = [[XJTimePickView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-40, (SCREEN_HEIGHT-425)/2)];
        __weak typeof(self) weakSelf = self;
        _startTimePickView.calendarChangeBlock = ^(NSString *changeTime) {
            weakSelf.startTime = changeTime;
        };
    }
    return _startTimePickView;
}

- (XJTimePickView *)endTimePickView{
    if (!_endTimePickView) {
        __weak typeof(self) weakSelf = self;
        _endTimePickView = [[XJTimePickView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-40, (SCREEN_HEIGHT-425)/2)];
        _endTimePickView.calendarChangeBlock = ^(NSString *changeTime) {
            weakSelf.endTime = changeTime;
        };
    }
    return _endTimePickView;
}

-(void)onClickCheckDate:(id)tap{
    _dateContentView.hidden = NO;
}

-(void)cancelChooseDate:(id)tap{
    _dateContentView.hidden = YES;
}


-(void)confirmChooseDate:(id)tap{
    if(!_startTime || _startTime.length < 4){
        _startTime = [NSString stringWithFormat:@"%@-%@-%@",
                      _startTimePickView.choosedYear,_startTimePickView.choosedMonth,_startTimePickView.chooseDay];
    }
    
    if(!_endTime || _endTime.length < 4){
        _endTime = [NSString stringWithFormat:@"%@-%@-%@",
                    _endTimePickView.choosedYear,_startTimePickView.choosedMonth,_startTimePickView.chooseDay];
    }
    
    _dateContentView.hidden = YES;
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:8]];//解决8小时时间差问题
    NSDate *sDate = [dateFormatter dateFromString:_startTime];
    NSDate *eDate = [dateFormatter dateFromString:_endTime];
    NSComparisonResult result =[sDate compare:eDate];
    
    switch (result) {
        case NSOrderedAscending:
            _startDate.text = _startTime;
            _endDate.text  = _endTime;
            break;
        case NSOrderedDescending:
            [MBProgressHUD showPromptWithAutoHideInView:self.view message:@"起始时间不能大于结束时间"];
            break;
        case NSOrderedSame:
            _startDate.text = _startTime;
            _endDate.text  = _endTime;
            break;
        default:
            break;
    }
    
}
@end
